//
//  GLPresetDelegate.m
//  HGLAnimation
//
//  Created by huang long on 17/1/18.
//  Copyright © 2017年 huang gu long. All rights reserved.
//

#import "GLTransitioningDelegate.h"
#import "GLBaseAnimatedTransition.h"
#import "GLDismissAnimatedTransition.h"
#import "GLPopoverPresentationController.h"
@interface GLTransitioningDelegate ()

@property(nonatomic , strong)GLBaseAnimatedTransition * baseTransition;

@property(nonatomic , assign)GLTransitioningPresentType type;

@end

@implementation GLTransitioningDelegate

+ (instancetype)shareDelegate{
    
    static dispatch_once_t onceToken;
    static id instance;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
    });
    return instance;
}

- (instancetype)transitionWithType:(GLTransitioningPresentType)type{
    
    self.type = type;
    
    return self;
}

- (instancetype)transitionWithInstance:(GLBaseAnimatedTransition *)instance{
    self.baseTransition = instance;
    return self;
}

- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
    if (self.baseTransition) {
        return self.baseTransition;
    }
    GLBaseAnimatedTransition *m = [[GLBaseAnimatedTransition alloc] init];
    return m;
}

- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{
    if (self.baseTransition) {
        return self.baseTransition;
    }
    GLBaseAnimatedTransition *m = [[GLDismissAnimatedTransition alloc] init];

    return m;
    
    
}


- (nullable id <UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id <UIViewControllerAnimatedTransitioning>)animator{
    return nil;
}

- (nullable id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator{
    return nil;
}

//该  方法在 8.0之后才会出现
- (nullable UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(nullable UIViewController *)presenting sourceViewController:(UIViewController *)source NS_AVAILABLE_IOS(8_0){
    if (self.insetsObject){
        GLPopoverPresentationController * pop =  [[GLPopoverPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
        pop.insetsObject = self.insetsObject;
        return pop;
    }
    return nil;
}

#pragma mark - UINavigationControllerDelegate
- (id<UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController{
    return nil;
}

- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC{
    return nil;
}

@end
